WOLF core
WOLF: A Modular Estimation Framework for Robotics
XXXXXXXXXXXXXXXXXXXXXXXXvoid(0)" frameborder="0" name="MSearchResults" id="MSearchResults">
state_quaternion.h
Go to the documentation of this file.
1// WOLF - Copyright (C) 2020-2026
2// Institut de Robòtica i Informàtica Industrial, CSIC-UPC.
3// Authors: Joan Solà Ortega (jsola@iri.upc.edu) and
4// Joan Vallvé Navarro (jvallve@iri.upc.edu)
5// All rights reserved.
6//
7// This file is part of WOLF: http://www.iri.upc.edu/wolf
8// WOLF is free software: you can redistribute it and/or modify
9// it under the terms of the GNU General Public License version 3
10// as published by the Free Software Foundation.
11//
12// This program is distributed in the hope that it will be useful,
13// but WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15// GNU General Public License for more details.
16//
17// You should have received a copy of the GNU General Public License
18// along with this program. If not, see <http://www.gnu.org/licenses/>.
19#pragma once
20
23
24namespace wolf
25{
29{
30 public:
33 StateQuaternion(bool _fixed = false, bool _transformable = true);
34
37 StateQuaternion(const Eigen::VectorXd& _state, bool _fixed = false, bool _transformable = true);
38
41 StateQuaternion(const Eigen::Quaterniond& _quaternion, bool _fixed = false, bool _transformable = true);
42 ~StateQuaternion() override;
43
46 static Eigen::VectorXd Identity();
48
49 void setIdentity(bool _notify = true) override;
50 Eigen::VectorXd identity() const override;
51
52 virtual void transform(const VectorComposite& _transformation) override;
53};
54
55inline StateQuaternion::StateQuaternion(const Eigen::Quaterniond& _quaternion, bool _fixed, bool _transformable)
56 : StateBlock("StateQuaternion",
57 _quaternion.coeffs(),
58 _fixed,
60 _transformable)
61{
62 state_.normalize();
63}
64
65inline StateQuaternion::StateQuaternion(const Eigen::VectorXd& _state, bool _fixed, bool _transformable)
66 : StateBlock("StateQuaternion",
67 _state,
68 _fixed,
70 _transformable)
71{
72 if (state_.size() != 4) throw std::runtime_error("The quaternion state vector must be of size 4!");
73
74 state_.normalize();
75}
76
77inline StateQuaternion::StateQuaternion(bool _fixed, bool _transformable)
78 : StateBlock("StateQuaternion",
79 4,
80 _fixed,
82 _transformable)
83{
84 state_ = Eigen::Quaterniond::Identity().coeffs();
85}
86
88
89inline void StateQuaternion::setIdentity(bool _notify)
90{
91 setState(Eigen::Quaterniond::Identity().coeffs(), _notify);
92}
93
94inline Eigen::VectorXd StateQuaternion::Identity()
95{
96 return Eigen::Quaterniond::Identity().coeffs();
97}
98
99inline Eigen::VectorXd StateQuaternion::identity() const
100{
101 return Eigen::Quaterniond::Identity().coeffs();
102}
103
104inline void StateQuaternion::transform(const VectorComposite& _transformation)
105{
106 if (transformable_)
107 setState(
108 (Eigen::Quaterniond(_transformation.at('O').data()) * Eigen::Quaterniond(getState().data())).coeffs());
109}
110
111} // namespace wolf
Local parametrization for quaternions.
Definition: local_parametrization_quaternion.h:54
State block: a state vector of a variable of the nonlinear optimization.
Definition: state_block.h:73
bool transformable_
Flag to indicate if the state block can be transformed to another reference frame.
Definition: state_block.h:89
void setState(const Eigen::VectorXd &_state, const bool _notify=true)
Sets the state vector.
Definition: state_block.cpp:25
Eigen::VectorXd getState() const
Returns the state vector.
Definition: state_block.h:322
Eigen::VectorXd state_
State vector storing the state values.
Definition: state_block.h:80
State block of a unit quaternion (3D orientation), stored as (x, y, z, w)
Definition: state_quaternion.h:29
~StateQuaternion() override
Definition: state_quaternion.h:87
WOLF_STATE_BLOCK_CREATE(StateQuaternion)
static Eigen::VectorXd Identity()
Returns the identity quaternion.
Definition: state_quaternion.h:94
void setIdentity(bool _notify=true) override
Sets the state to the identity element.
Definition: state_quaternion.h:89
virtual void transform(const VectorComposite &_transformation) override
Transforms the state to another reference frame (if transformable)
Definition: state_quaternion.h:104
Eigen::VectorXd identity() const override
Returns the identity element of the state.
Definition: state_quaternion.h:99
StateQuaternion(bool _fixed=false, bool _transformable=true)
Constructor, with the identity quaternion.
Definition: state_quaternion.h:77
Composite of state vectors.
Definition: vector_composite.h:29
Definition: jet.h:1355
Definition: capture_base.h:23
@ DQ_LOCAL
Local delta: q+ = q * exp_q(dtheta)
Definition: local_parametrization_quaternion.h:36